package com.example.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.User;
import com.example.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;

    // 分页查询：GET /user/page?page=1&size=5
    @GetMapping("/page")
    public IPage<User> page(@RequestParam(defaultValue = "1") long page,
                            @RequestParam(defaultValue = "5") long size) {
        Page<User> p = Page.of(page, size);
        return userService.page(p);
    }

    // 新增
    @PostMapping
    public boolean add(@RequestBody User user) {
        return userService.save(user);
    }


    // 新增详情接口
    @PostMapping
    public User add(Long id) {
        return userService.getById(id);
    }


    // 删除接口
    @PostMapping
    public boolean del(Long id) {
        return userService.removeById(id);
    }


    


}